package com.kc.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kc.bean.UserAccount;
import com.kc.mapper.UserAccountMapper;
import com.kc.service.IUserAccountService;
import com.kc.util.JWTutil;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.CompletableFuture;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2019-10-09
 */
@Service
public class UserAccountServiceImpl extends ServiceImpl<UserAccountMapper, UserAccount> implements IUserAccountService {

    @Resource
    private UserAccountMapper accountMapper;

    /**
     * 接收token然后吧token中的用户唯一可见id取出来再去返回用户的主ID
     * @param token
     * @return
     */
    @Override
    public String getAccount(String token) {
        String id = JWTutil.GetPayload(token,"visibleId");
        return accountMapper.getAccount(Wrappers.<UserAccount>lambdaQuery().eq(UserAccount::getUserUniqueIdIdentifier,id));
    }

    @Override
    public CompletableFuture<Integer> inst(UserAccount userAccount) {
        int i = accountMapper.insert(userAccount);
        return CompletableFuture.completedFuture(i);
    }

    @Override
    public UserAccount getUserAccount(String id) {
        return accountMapper.getUserAccount(Wrappers.<UserAccount>lambdaQuery().eq(UserAccount::getUserId,id));
    }

}
